package com.example.addressbook.dao;

import com.example.addressbook.dto.GroupingInfo;

import com.example.addressbook.dto.linkmanInfo;
import com.example.addressbook.entities.Grouping;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GroupRepository extends CrudRepository<Grouping,Long> {
    @Override
    public List<Grouping> findAll();

    @Query(nativeQuery = true,value ="SELECT B.GROUP_ID ,GROUP_NAME  AS label, COUNT(c.LINKMAN_ID ) AS value " +
            "FROM GROUPING_LINKMAN B " +
            "LEFT JOIN GROUPING  A ON A.GROUP_ID=B.GROUP_ID " +
            " LEFT JOIN LINKMAN  C ON C.Linkman_ID =B.GROUP_ID " +
            "GROUP BY GROUP_NAME " +
            "order by B.GROUP_ID asc;" )
    List<GroupingInfo> GroupingInfo();

    Grouping findById(long thId);
}
